package com.will.network.images;

import android.graphics.Bitmap;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader.ImageCache;

/**
 * Basic LRU Memory cache.
 * 
 * @author Will
 *
 */
public class ImageLruMemoryCache extends LruCache<String, Bitmap> implements ImageCache{



    private final String TAG = "ImageLruMemoryCache";

	public static int getDefaultLruCacheSize() {
		final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
		return maxMemory / 8;
	}

	public ImageLruMemoryCache() {
		this(getDefaultLruCacheSize());
	}

	public ImageLruMemoryCache(int maxSize) {

        super(maxSize);
	}
	
	@Override
	protected int sizeOf(String key, Bitmap value) {
        return (value.getRowBytes() * value.getHeight()) / 1024;
	}
	
	@Override
	public Bitmap getBitmap(String key) {
		return get(key);
	}

	@Override
	public void putBitmap(String key, Bitmap bitmap) {
		put(key, bitmap);
	}

}
